<template>
	<orh-table reload @on-reload="refresh" search @on-search="searchmt" add="teacher_information_add" pages @on-add="addSilde" :pageDate="pageDate" @on-page-change="Information">
	
		<Table ref='tableExcel' :border="showBorder" :data="TeacherList" :columns="columns1" slot="table" :loading="tableload"></Table>
		<Modal v-model="prompt" title="数据删除" :loading="loading" @on-ok="asyncOK" slot="others">
			<p>{{ cont }}</p>
		</Modal>
		<orh-sidebar v-model="isShow" :title="titles" cover slot="others">
			<component :is="content" :user_id="user_id" @requery="requery"></component>
		</orh-sidebar>
	
	</orh-table>
</template>

<script>
	export default {
		name:'teacher-teacherinformation',
		components: {
			InformationDetail: resolve => {
				require(["$m/Teacher/TeacherInformation/InformationDetail.vue"], resolve);},
			InformationAdd: resolve => {
				require([
					'./InformationAdd.vue'
				], resolve);
			},
			InformationEdit: resolve => {
				require([
					'./InformationEdit.vue'
				], resolve);
			},
			InformationExport: resolve => {
				require([
					'./InformationExport.vue'
				], resolve);
			},
			InformationImport: resolve => {
				require([
					'./InformationImport.vue'
				], resolve);
			}
		},
		data() {
			return {
				TeacherList: [],
				imortList:[],
				prompt: false,
				loading: true,
				showBorder: false,
				tableload: true,
				isShow: false,
				content: '',
				cont: '您确定要删除这些数据吗',
				titles: null,
				user_id: null,
				del: null,
				pageDate: {
					total: 0,
					current_page: 1,
					per_page: 20
				},
				columns1: [
                    {
						title: '头像',
						width: 100,
						key: 'imgphotos',
						align: 'center',
						render: (h, params) => {
							return h('div', {
								attrs: {
									style: 'width: 80px;height: 80px;'
								},
							}, [
								h('img', {
									props: {
										type: 'primary',
										size: 'small'
									},
									attrs: {
										src: params.row.imgphotos != null ? params.row.imgphotos : 'http://1.180.78.87/dc/framework/common/images/noPic_150x150.jpg',
										style: 'width: 90%;height: 90%;border-radius: 2px;'
	
									},
									style: {},
								}),
							]);
						}
					},
					{
						title: '身份证号',
						minWidth: 180,
						key: 'idcard',
						align: 'center'
					},
					{
						title: '姓名',
						width: 120,
						render:(h,params)=> {
							return h('span',params.row.teacher_name?params.row.teacher_name.zh?params.row.teacher_name.zh:params.row.teacher_name.mn:'')
						},
						align: 'center'
					},
					{
						title: '性别',
						width: 80,
						align: 'center',
						render:(h,params)=> {
							let gender = params.row.gender;
							return h('span',gender)
						}
						
					},
					{
						title: '民族',
						width: 80,
						align: 'center',
						render:(h,params)=> {
							let name = params.row.nation;
							return h('span',name)
						}
						
					},
					{
						title: '联系号码',
						minWidth: 120,
						key: 'telnumber',
						align: 'center'
					},
					{
						title: '邮箱',
						width: 150,
						key: 'email',
						align: 'center'
					},
					{
						title: '在岗状态',
						width: 100,
						align: 'center',
						render:(h,params)=> {
							let name = params.row.workstatus?(params.row.workstatus.zh?params.row.workstatus.zh:params.row.workstatus.mn):''
							return h('span',name)
						},		
					},
					{
						title: '操作',
						key: 'operation',
						align: 'center',
						fixed: 'right',
						width: 180,
						render: (h, params) => {
							return h('div', [
								h(
									'Button', {
										props: {
											type: 'success',
											size: 'small'
										},
										style: {
											marginRight: '5px'
										},
										on: {
											click: () => {
												this.detail(params.row.id);
											}
										}
									},
									'查看'
								),
								h(
									'Button', {
										directives: [{
											name: 'button',
											value: 'teacher_information_edit'
										}],
										props: {
											type: 'primary',
											size: 'small'
										},
										style: {
											marginRight: '5px'
										},
										on: {
											click: () => {
												this.update(params.row.id);
											}
										}
									},
									'编辑'
								),
								h(
									'Button', {
										directives: [{
											name: 'button',
											value: 'teacher_information_delete'
										}],
										props: {
											type: 'error',
											size: 'small'
										},
										style: {
											marginRight: '5px'
										},
										on: {
											click: () => {
												this.remove(params.row.id);
											}
										}
									},
									'删除'
								)
								
							]);
						}
					}
				],

                searchValue: ''
			};
		},
		methods: {
			addSilde() {
				this.isShow = true;
				this.titles = '添加教职工信息';
				this.content = 'InformationAdd';
			},
			update(index) {
				this.titles = '修改教职工信息';
				this.isShow = true;
				this.user_id = index;
				this.content = 'InformationAdd';
			},
			detail(index) {
				this.titles = '教职工信息详情';
				this.isShow = true;
				this.user_id = index;
				this.content = 'InformationDetail';
			},
			searchmt(str) {
				this.tableload = true
                this.searchValue = str
				this.Information (1)
			},
			refresh () {
				this.searchValue = ''
				this.tableload = true;
				this.Information(this.pageDate.current_page);
			},
			//列表
			Information(page) {
				let url = ''
				if (this.searchValue) {
					let obj = {
						zh: this.searchValue
					}
					url = `api/teacher/information/getList?page=${page}&limit=10&teacher_name=${JSON.stringify(obj)}`
				} else {
					url = `api/teacher/information/getList?page=${page}&limit=10`
				}
				this.$http.get(url).then(val => {
					this.TeacherList = val.data
					this.pageDate.total = val.count
					this.pageDate.per_page = val.limit
					this.pageDate.current_page = val.page
					this.tableload = false
				}).catch(err => {
					this.tableload = false
				});
			},
			remove(index) {
				this.prompt = true
				this.del = index
			},
			asyncOK() {
				this.$http.delete('api/teacher/information/delById/' + this.del).then(val => {
					this.prompt = false;
					this.tableload = true;
					this.Information(this.pageDate.current_page);
					
				}).catch(err =>{
				});
			},
	
			//单条数据删除
			
			requery(val) {
				if (val == true) {
					this.child = false;
					this.isShow = false;
					this.tableload = true;
					this.Information(this.pageDate.current_page);
				}
			},	
			
		},
		mounted() {
			this.Information(1);
		}
	};
</script>




